<template>
	<el-container>
		<el-header class='x-header'>
			<b class="title">{{ page_info.title }}</b>
			<el-button v-if="$route.query.callback_url" size="mini" icon="el-icon-back" @click="g_page.funcBack">
				返回
			</el-button>
			<ExprotExcel api_url="/xadmin/app_car/app_car__order__list/export" :api_data="form_q"></ExprotExcel>
			<el-button size="mini" type="warning" icon="el-icon-edit-outline" @click="funcDone">订单完成</el-button>
			<el-button size="mini" icon="el-icon-refresh" @click="g_page.funcReload()">刷新</el-button>
		</el-header>
		<el-main class='x-main'>
			<el-form :inline="true" :model="form_q" size="mini">
				<el-form-item label="订单号">
					<el-input v-model="form_q.compOrderID"></el-input>
				</el-form-item>
				<el-form-item label="姓名">
					<el-input v-model="form_q.compUserName" placeholder="姓名"></el-input>
				</el-form-item>
				<el-form-item label="手机">
					<el-input v-model="form_q.compUserPhone" placeholder="手机号码"></el-input>
				</el-form-item>
				<el-form-item label="车牌">
					<el-input v-model="form_q.compSkuCarNo" placeholder="车牌号"></el-input>
				</el-form-item>
				<el-form-item label="状态">
					<el-select filterable clearable v-model="form_q.compState" placeholder="请选择">
						<el-option v-for="(item,key) in page_info.list_state"
								   :label="item"
								   :key="key"
								   :value="key">
						</el-option>
						<el-option label="用车中" key="5" value="5">
						</el-option>
					</el-select>
				</el-form-item>
				<br/>
				<el-form-item label="用车方式">
					<el-select filterable clearable v-model="form_q.compType" placeholder="请选择">
						<el-option label="分时" key="0" value="0"></el-option>
						<el-option label="套餐" key="1" value="1"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="用车时间">
					<el-date-picker
						style="width: 200px;"
						v-model="form_q.compUseDateBegin"
						type="datetime"
						placeholder="选择开始时间"
						:picker-options="g_cc.picker_options"
						default-time="00:00:00"
						value-format="yyyy-MM-dd HH:mm:ss">
					</el-date-picker>
					至
					<el-date-picker
						style="width: 200px;"
						v-model="form_q.compUseDateEnd"
						type="datetime"
						placeholder="选择结束时间"
						default-time="23:59:59"
						value-format="yyyy-MM-dd HH:mm:ss">
					</el-date-picker>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="g_page.funcSearch">搜索</el-button>
				</el-form-item>
			</el-form>
			<div class="table-wrap">
				<el-table stripe ref="multipleTable" tooltip-effect="dark"
						  @selection-change="g_page.funcTableSelectionChange"
						  :data="list_data">
					<el-table-column type="selection"></el-table-column>
					<el-table-column label="订单号">
						<template slot-scope="data">
							<div v-html="data.row.corder_id"></div>
						</template>
					</el-table-column>
					<el-table-column label="用车方式">
						<template slot-scope="data">
							<div>{{ data.row.type }}</div>
						</template>
					</el-table-column>
					<el-table-column label="客户">
						<template slot-scope="data">
							<div v-html="data.row.cuser_name"></div>
							<div style="color:blue;" v-html="data.row.cuser_phone"></div>
							<!--							<div v-html="data.row.corder_openid"></div>-->
						</template>
					</el-table-column>
					<el-table-column label="车型">
						<template slot-scope="data">
							<div v-html="data.row.cspu_name"></div>
						</template>
					</el-table-column>
					<el-table-column label="车牌号">
						<template slot-scope="data">
							<div v-html="data.row.csku_car_no"></div>
						</template>
					</el-table-column>
					<el-table-column label="无忧保障">
						<template slot-scope="data">
							<div v-if="data.row.corder_safe==1">
								已购买
							</div>
							<div v-else>
								未购买
							</div>
						</template>
					</el-table-column>
					<el-table-column label="用车时间">
						<template slot-scope="data">
							<div v-html="data.row.corder_use_date"></div>
						</template>
					</el-table-column>
					<el-table-column label="套餐">
						<template slot-scope="data">
							<div v-if="data.row.corder_pay_plan_h<=0">
								未购买
							</div>
							<div v-else>
								<div>金额：{{data.row.corder_pay_plan_price}}</div>
								<div>时长：{{data.row.corder_pay_plan_h}}小时</div>
							</div>
						</template>
					</el-table-column>
					<el-table-column label="用车时长">
						<template slot-scope="data">
							<div v-if="data.row.corder_back==1">{{ data.row.corder_minute }}分钟</div>
							<div style="color:blue;" v-if="data.row.corder_back_admin==1">强制还车</div>
						</template>
					</el-table-column>
					<el-table-column label="优惠券">
						<template slot-scope="data">
							<div v-if="data.row.corder_price_down_coupon>0">
								已使用
							</div>
						</template>
					</el-table-column>
					<el-table-column label="订单支付金额">
						<template slot-scope="data">
							<div v-if="data.row.corder_back==1" style="color: blue;">{{ data.row.original_price }}元
							</div>
						</template>
					</el-table-column>
					<el-table-column label="状态">
						<template slot-scope="data">
							{{ data.row.state }}
						</template>
					</el-table-column>
					<el-table-column fixed="right" label="操作">
						<template slot-scope="data">
							<el-button type="text" size="mini" @click="g_page.funcRedirectEdit('app_car__order__edit',data.row)">
								详情
							</el-button>
						</template>
					</el-table-column>
				</el-table>
				<a target="_blank"></a>
			</div>
		</el-main>
		<!---->
		<!---->
		<!-- 分页 -->
		<el-footer v-if="page_show" class="x-page">
			<el-pagination class="paging" background layout="total, sizes, prev, pager, next, jumper"
						   @current-change="g_page.funcPageChange" :page-sizes="[page_size]"
						   :current-page="page_index" :page-size="page_size" :total="page_total">
			</el-pagination>
		</el-footer>
		<!---->
		<!---->
		<!-- 弹框 -->
		<el-dialog :title="form.app_idx+'配置'" :visible.sync="form_dialog_visible" width="70%">
			<el-form ref="form" :rules="form_rules" :model="form" size="mini" label-width="15%">
				<el-form-item label="入口链接" v-if="!g_page.funcIsAdminAdd()">
					<el-input :disabled="true" v-model="form.oauth_url"/>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click="g_page.funcBack" size="mini">取消</el-button>
				<el-button type="success" @click="g_page.funcSave" size="mini">保存</el-button>
			</div>
		</el-dialog>
		<!---->
		<!---->
		<!---->
	</el-container>
</template>


<script>
	import ExprotExcel from '@/components/ExprotExcel'

	export default {
		components: {
			ExprotExcel
		},
		data() {
			let page_data = { super_uid: '' }
			//
			page_data = this.g_cc.funcGetInitData(page_data)
			//
			return page_data
		},
		mounted() {
			console.log('mounted')
			//
			this.g_page.funcSetVue(this)
			// 应用ID
			this.g_page.funcSetApiUrlList('/xadmin/app_car/app_car__order__list')
			this.g_page.funcSetApiUrlExport('/xadmin/app_car/app_car__order__list/export')
			//页码
			this.g_page.funcSetPageSize(20)
			//搜索
			this.form_q = {
				'compKw': ''
			}
			this.g_page.funcGetList()
			//
			this.form_rules = {
				acc_uidX: [
					{
						required: true,
						message: '必填',
						trigger: 'blur'
					}
				]
			}
			//
		},
		methods: {
			////////////////////
			//订单完成
			funcDone() {
				let ids = this.g_page.funcGetIds()
				if (ids == '') {
					this.g_cc.func_alert('至少选择一项', 'info')
					return
				}
				this.g_cc.func_confirm('确定吗？', () => {
					this.g_cc.func_axios({
						url: '/xadmin/app_car/app_car__order__list/funcDone',
						data: {
							ids: ids
						},
						success: (res) => {
							//
							if (res.data.errcode == 0) {
								if (res.data.err.length > 0) {
									let errmsg = ''
									for (let key in res.data.err) {
										let val = res.data.err[key]
										errmsg += `${val}<br/>`
									}
									this.g_cc.func_alert(errmsg, 'error', () => {
											this.g_page.funcGetList()
										}
									)
								} else {
									this.g_cc.func_alert('成功', 'success', () => {
										this.g_page.funcGetList()
									})
								}
							} else {
								this.g_cc.func_alert(res.data.errmsg, 'error')
							}
						}
					})
				})
				////////////
			}
			////////////////////
		}
	}
</script>

